from flask import Blueprint,jsonify

from utils.db import db1

import json

from utils.redis_bp import r

work_bp = Blueprint('work',__name__)

@work_bp.route('/getworkflow')
def getworkflow():
    sql = "select * from workflow"

    res = db1.find_all(sql)

    return jsonify({'code':200,'list':res})



# 获取数据源接口
@work_bp.route('/getresourcedata')
def getresourcedata():
    # 首次先从数据库中取值
    values = r.get_to('resourcedata')

    print(values)

    if values:
        list = eval(values)

    else:
        sql = "select * from data_resource"
        res = db1.find_all(sql)
        list = []
        if res:
            for i in res:
                dict = {'id':i['id'],'name':i['name']}
                sql1 = "select id,name from %s" % (i['tablename'])

                res1 = db1.find_all(sql1)

                dict['mes'] = res1

                list.append(dict)

        r.set_to('dataresource',json.dumps(list))

    return jsonify({'code':200,'list':list})



